package com.yyfax.ph.web;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

public class WebModel extends Model {
	private static final String TAG = WebModel.class.getSimpleName();

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.getWebUrl(token, new Option((String) params));
	}

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		WebResult webResult = cast(obj);
		EventAgent.post(webResult);
	}

	public interface Service {
		@POST("sys/page")
		Observable<WebResult> getWebUrl(@Header("token") String token, @Body Option otion);
	}

	public static class WebResult extends BaseResultEntity<String> {

	}

	protected static class Option {
		String type;

		public Option(String type) {
			this.type = type;
		}
	}

}
